﻿namespace Brouteforce.Utilities {

    public class MonitoredProperty<T> {
        private T _property;
        private int _lastKnowedChangedLoopIndex;

        public MonitoredProperty(T property) {
            _property = property;
            _lastKnowedChangedLoopIndex = BFGame.LoopIndex;
        }

        public T Property {
            get { return _property; }
            set {
                _lastKnowedChangedLoopIndex = BFGame.LoopIndex;
                _property = value;
            }
        }


        public int ChangedIn() {
            return _lastKnowedChangedLoopIndex;
        }

        public bool IsChangedSince(int loopIndex) {
            if (_lastKnowedChangedLoopIndex == 0) return false;
            return (_lastKnowedChangedLoopIndex == loopIndex);
        }

    }
}
